import {Component, OnInit} from '@angular/core';
import {Device} from "../model/Device";
import {ActivatedRoute} from "@angular/router";
import {DeviceService} from "../device-component/device-component.service";

@Component({
  selector: 'app-simulation-component',
  templateUrl: './simulation-component.component.html',
  styleUrls: ['./simulation-component.component.scss'],
  providers: [DeviceService]
})
export class SimulationComponentComponent implements OnInit {
  private message: string = '{\n' +
    '\t"deviceId": "1",\n' +
    '\t"data": {\n' +
    '\t\t"p1": 1,\n' +
    '\t\t"p2": 3\n' +
    '\t}\n' +
    '}';

  private result: string = '';

  private device: Device = new Device();

  constructor(private activatedRoute: ActivatedRoute, private deviceService: DeviceService) {
  }

  ngOnInit() {
    let id = this.activatedRoute.snapshot.params['id'];
    this.deviceService.get(id).subscribe(d => this.device = d);
  }

  doPublish() {
    this.deviceService.dataChange(this.message).subscribe(d => console.log(d))
  }

}
